<?php
if(!defined('IN_THANKPHP_SYSTEM')) exit('Access Denied!');

class urls extends base {
	private $url;
	private $url_model = array(
		'M'	=>	'index',
		'C'	=>	'index',
		'A'	=>	'index',
		'I'	=>	'index',
		'P'	=>	'index',
	);
	
	public function addType(){
		return;
	}
	
	public function dispatcher(){
		global $DEBUG;
		if($DEBUG)
		print 'url dispatch begin......<br/>';
	}
	
	public function setDefault(){
		//
	}
	
	public function error(){
		print 'function not found!';
	}
	
	public function mapUrl(){
		$len_add = thankphp::$CONFIG['DIR']?2:1;
		$instance = substr(thankphp::$CONFIG['URL'],strlen(thankphp::$CONFIG['DIR'])+$len_add);
	 	$arr = split('/', $instance);
	 	$url = array();
	 	$i = 0;
	 	foreach($this->url_model AS $k => $v){
	 		if(isset($arr[$i]) && $arr[$i]){
	 			$url[$k] = $arr[$i];
	 		}else{
	 			$url[$k] = $v;
	 		}
	 		$i++;
	 	}
	 	for($i=5,$len=count($arr); $i < $len; $i++){
	 		$url['P'] .= '+'.$arr[$i];
	 	}
	 	return $url;
	}
	
	public function back($msg){
		global $TEMPLATE_DIRS;
		//back to the previous page
		include_once $TEMPLATE_DIRS[0].'/system/back.php';
		exit;
	}
	
	public function checkDir($dir){
		if(!is_dir($dir)){
			return false;
		}
		return true;
	}
}
